package view;

import view.kasse.KasseEventListePanel;
import java.awt.event.KeyEvent;
import model.EventSalg;
import utility.DoubleRestrictionDocument;

/**
 *
 * @author Jeppe
 */
public class AntalFremmoedtePopup extends javax.swing.JFrame {

    private final KasseEventListePanel kasseEventListePanel;
    private final EventSalg eventSalg;

    /**
     * Creates new form AntalFremmoedtePopup
     *
     * @param kasseEventListePanel
     * @param eventSalg
     */
    public AntalFremmoedtePopup(KasseEventListePanel kasseEventListePanel, EventSalg eventSalg) {
        initComponents();
        this.kasseEventListePanel = kasseEventListePanel;
        this.eventSalg = eventSalg;
        setLocationRelativeTo(kasseEventListePanel);
        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        antalFremmoedteTxt = new javax.swing.JTextField();
        okKnap = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        antalFremmoedteTxt.setDocument(new DoubleRestrictionDocument(13,antalFremmoedteTxt));
        antalFremmoedteTxt.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        antalFremmoedteTxt.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        antalFremmoedteTxt.setText("0");
        antalFremmoedteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                antalFremmoedteTxtKeyReleased(evt);
            }
        });

        okKnap.setText("OK!");
        okKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okKnapActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(145, 145, 145)
                .addComponent(okKnap, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(antalFremmoedteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(okKnap, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(antalFremmoedteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void antalFremmoedteTxtKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_antalFremmoedteTxtKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            eventSalg.getEvent().setAntalFremmødte(Integer.parseInt(antalFremmoedteTxt.getText()));
            kasseEventListePanel.setLabels();
            setVisible(false);
        }
    }//GEN-LAST:event_antalFremmoedteTxtKeyReleased

    private void okKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okKnapActionPerformed
        eventSalg.getEvent().setAntalFremmødte(Integer.parseInt(antalFremmoedteTxt.getText()));
        kasseEventListePanel.setLabels();
        setVisible(false);
    }//GEN-LAST:event_okKnapActionPerformed
//
//    /**
//     * @param args the command line arguments
//     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(AntalFremmoedtePopup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(AntalFremmoedtePopup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(AntalFremmoedtePopup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(AntalFremmoedtePopup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new AntalFremmoedtePopup().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField antalFremmoedteTxt;
    private javax.swing.JButton okKnap;
    // End of variables declaration//GEN-END:variables
}
